package com.jian.java.controller;

import com.jian.java.bean.CommonResult;
import com.jian.java.bean.Payment;
import com.jian.java.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Jiange
 * @create 2021-06-02-16:15
 */
@RestController
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @GetMapping("/payment/add")
    public CommonResult create(Payment payment){
        int i = paymentService.create(payment);
        if(i>0){
            return new CommonResult(200,"成功创建",i);
        }else {
            return new CommonResult(444,"失败",null);
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult getId(@PathVariable("id") int id){
        Payment paymentById = paymentService.getPaymentById(id);
        if(paymentById != null){
            return new CommonResult(200,"成功找到",paymentById);
        }else {
            return new CommonResult(444,"没有找到",null);
        }
    }

    @GetMapping("/payment/getall")
    public CommonResult getAll(){
        List<Payment> all = paymentService.getAll();
        return new CommonResult(200,"成功找到",all);
    }

    @GetMapping("/port")
    public int Getport(){
        return port;
    }

    @Value("${server.port}")
    private int port;
}
